package org.budo.cmbc.sdk.entity;

import lombok.extern.slf4j.Slf4j;
import org.budo.xml.XmlObject;

/**
 * @author lmw
 */
@Slf4j
public class BatchCostReimbResponse extends AbstractCmbcResponse {
    private static final long serialVersionUID = -2830132208183730535L;

    public BatchCostReimbResponse(String responseXml) {
        this.setResponseBody(responseXml);
    }

    public String getTrnId() {
        XmlObject xDataBody = this.xDataBody(this.getResponseBody());

        if (null == xDataBody) {
            log.error("#34 xDataBody=" + xDataBody + ", responseBody=" + this.getResponseBody());
            return null;
        }

        XmlObject batchCostReimb = xDataBody.getChildNodeByName("batchCostReimb");
        if (null == batchCostReimb) {
            log.error("#30 xDataBody=" + xDataBody + ", responseBody=" + this.getResponseBody());
            return null;
        }

        return batchCostReimb.getChildNodeTextContentByName("trnId");
    }

    public String getInsId() {
        XmlObject xDataBody = this.xDataBody(this.getResponseBody());

        if (null == xDataBody) {
            log.debug("#41 xDataBody={}, responseBody={}", xDataBody, this.getResponseBody());
            return null;
        }

        XmlObject batchCostReimb = xDataBody.getChildNodeByName("batchCostReimb");
        if (null == batchCostReimb) {
            log.error("#47 xDataBody=" + xDataBody + ", responseBody=" + this.getResponseBody());
            return null;
        }

        return batchCostReimb.getChildNodeTextContentByName("insId");
    }

    @Override
    public String toString() {
        return super.toString() + ", responseBody=" + this.getResponseBody();
    }
}

//<CMBC trnCode="batchCostReimb" security="none" lang="chs" header="100" version="100">
//<responseHeader>
//  <status>
//    <code>0</code>
//    <severity>info</severity>
//    <message>ok</message>
//  </status>
//  <dtServer>2021-04-16 15:22:42</dtServer>
//  <userKey>N</userKey>
//  <dtDead/>
//  <language>chs</language>
//</responseHeader>
//<xDataBody>
//  <batchCostReimb>
//    <trnId>TJ21416152242215</trnId>
//    <insId>210416152242215</insId>
//  </batchCostReimb>
//</xDataBody>
//</CMBC>
// <trnId> 原值返回
// <insId> 流水号
